﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>MLSLab</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <!--<link rel="stylesheet" href="layui/css/layui.css" media="all">
    <link rel="stylesheet" href="fontawesome/css/fontawesome.min.css" media="all">
    <link rel="stylesheet" href="fontawesome/css/solid.css" media="all">
    <link rel="stylesheet" href="css/style.css" media="all">
    <link rel="stylesheet" href="css/style-admin.css" media="all">
    <link href="css/style11.css" rel="stylesheet" />-->
    <!--<link href="../layui-v2.6.8/layui/css/layui.css" rel="stylesheet" media="all"/>-->
    <link href="../layui/css/layui.css" rel="stylesheet" media="all" />
    <link href="css/Tkcss/fontawesome.min.css" rel="stylesheet" media="all" />
    <link href="css/Tkcss/solid.css" rel="stylesheet" media="all"/>
    <link href="css/Tkcss/style.css" rel="stylesheet" media="all"/>
    <link href="css/Tkcss/style-admin.css" rel="stylesheet" media="all"/>
    <link href="css/Tkcss/style11.css" rel="stylesheet" media="all"/>
    <style type="text/css">
        .task {
            border: 2px solid #f2f2f2;
            /*width:600px;*/
        }
        .window-page {
            width:720px;
            height:770px;
        }
        .editbox .btnbox {
          /*padding-left:-500px;*/
          margin-left:-250px;
        }

        .task_wraper.homework .task {
            width: 720px;
            height: 770px;
            /*      width: 500px;
            height: 610px;*/
            margin-left: -50px;
            margin-top: -15px;
            /* text-align: center;*/
        }
      

    </style>
</head>
<body>

    <!--[if lt IE 9]>
      <script src="js/html5.min.js"></script>
      <script src="js/respond.min.js"></script>
     <![endif]-->
    <div class="window-page">
        <div class="layui-row">
            <div class="layui-col-md12">
                <form class="layui-form" action="">

                    <div class="layui-form-item">
                        <!--<label class="layui-form-label">测试题设置</label>-->
                        <div class="layui-input-block">
                            <div id="homework" class="task_wraper homework">

                                <div class="task">
                                    <!--<div class="toppic"><b></b><p>第1题</p></div>-->
                                    <div class="editbox">
                                        <!--<div class="edit_li">
                                            <div class="title"><sup></sup>习题类型：</div>
                                            <div class="cont">
                                                <input type="radio" name="examtype_" value="1" title="单选" lay-filter="examtype_">


                                            </div>
                                        </div>-->
                                        <hidden id="ids"></hidden>
                                        <div class="edit_li">
                                            <div class="title"><sup></sup>题目内容：</div>
                                            <div class="cont">
                                                <input id="Topic_" name="workname" type="text" class="input_def" value="" placeholder="输入题目内容" />
                                            </div>
                                        </div>
                                        <div class="edit_li">
                                            <div class="title">题目图片：</div>
                                            <div class="cont">
                                                <div class="layui-upload">
                                                    <button type="button" class="layui-btn layui-btn-normal" id="test_">上传图片</button>
                                                    <span class="layui-word-aux">图片大小：290px*163px</span><br /><span id="imgname_"> </span>
                                                    <div class="layui-upload-list"><img class="layui-upload-img layui-upload-course-kpoints" id="demo1_"><p id="demoText_"></p></div>
                                                    <div style="width: 95px;">
                                                        <!--<div class="layui-progress layui-progress-big" lay-showpercent="yes" lay-filter="demo_">
                                                            <div class="layui-progress-bar" lay-percent=""></div>
                                                        </div>-->
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <DIV id="type1_">
                                            <div class="edit_li">
                                                <div class="title">A:</div>
                                                <div class="cont">
                                                    <input id="OptionA_" name="ExamAmswer" type="text" class="input_def" value="" placeholder="输入选项内容" />
                                                </div>
                                            </div>
                                            <div class="edit_li">
                                                <div class="title">B:</div>
                                                <div class="cont">
                                                    <input id="OptionB_" name="ExamAmswer" type="text" class="input_def" value="" placeholder="输入选项内容" />
                                                </div>
                                            </div>
                                            <div class="edit_li">
                                                <div class="title">C:</div>
                                                <div class="cont">
                                                    <input id="OptionC_" name="ExamAmswer" type="text" class="input_def" value="" placeholder="输入选项内容" />
                                                </div>
                                            </div>
                                            <div class="edit_li">
                                                <div class="title">D:</div>
                                                <div class="cont">
                                                    <input id="OptionD_" name="ExamAmswer" type="text" class="input_def" value="" placeholder="输入选项内容" />
                                                </div>
                                            </div>
                                            <div class="edit_li">
                                                <div class="title">E:</div>
                                                <div class="cont">
                                                    <input id="OptionE_" name="ExamAmswer" type="text" class="input_def" value="" placeholder="输入选项内容" />
                                                </div>
                                            </div>
                                            <div class="edit_li">
                                                <div class="title"><sup></sup>正确答案：</div>
                                                <div class="cont">
                                                    <input type="radio" name="Answer1_" value="A" title="A" />
                                                    <input type="radio" name="Answer1_" value="B" title="B" />
                                                    <input type="radio" name="Answer1_" value="C" title="C" />
                                                    <input type="radio" name="Answer1_" value="D" title="D" />
                                                    <input type="radio" name="Answer1_" value="E" title="E" />
                                                </div>
                                            </div>
                                        </DIV>



                                        <div id="btn_save" class="btnbox"><a class="btn_red_m style1" onclick="saves()">保存</a></div>

                                        <div id="btn_updateDel" class="btnbox" style="padding-left:100px;"><a class="btn_red_m style1" onclick="UpdateExam()">修改</a>&nbsp;&nbsp;&nbsp;<a class="btn_red_m style1" onclick="Del()">删除</a></div>
                                    </div>
                                </div>
                                <!--<a id="btn_work_add" class="btn_task_add"><b></b></a>-->
                            </div>
                        </div>
                    </div>


                </form>
            </div>
        </div>
    </div>
    <!--<script src="js/jquery-3.1.1.min.js" charset="utf-8"></script>-->
    <!--<script src="layui/layui.js" charset="utf-8"></script>-->
    <!--<script src="js/main-admin.js" charset="utf-8"></script>-->
    <!--<script src="../../js/Admin/Course.js"></script>-->
    <script src="js/jquery-3.1.1.min.js" charset="utf-8"></script>
    <script src="../layui/layui.js" charset="utf-8"></script>
    <!--<script src="../layui-v2.6.8/layui/layui.js" charset="utf-8"></script>-->


</body>
</html>
<script type="text/javascript">
    //layui.use(['form', 'layer', 'upload', 'element'], function () {
    //    var form = layui.form, layer = layui.layer, upload = layui.upload, element = layui.element, layedit = layui.layedit
    //    var index = layedit.build('LAY_demo', {
    //        tool: ['strong', 'italic', 'underline', 'del', '|', 'left', 'center', 'right'],
    //        height: 200
    //    });
    //    });
    var prourlid = 0;
    var virualpath = "../../";
    var layerindex = "";
    var Content = "";
    $(function () {
        layui.use(['form', 'layedit', 'laydate'], function () {
            var form = layui.form
                , layer = layui.layer
                , layedit = layui.layedit
            Content = layedit.build('Content', {
                height: 180, //设置编辑器高度
                tool: [
                    'strong' //加粗
                    , 'italic' //斜体
                    , 'underline' //下划线
                    , 'del' //删除线
                    , '|' //分割线
                    , 'left' //左对齐
                    , 'center' //居中对齐
                    , 'right' //右对齐
                    , 'help' //帮助
                ],
            });
        });

        var res = window.location.search;
        var resdata = res.split(",")
     
        if (res == "") {
            location.href = "index.html"
        } else {
           
            if (resdata.length <= 2) {
                prourlid = resdata[0].split("=")[1];
             
               
                layui.use(['form', 'layedit', 'laydate'], function () {
                    var form = layui.form
                        , layer = layui.layer
                        , layedit = layui.layedit
                    //layerindex = layer.load(1, {
                    //    shade: [0.1, '#fff'] //0.1透明度的白色背景
                    //});
                });
                GetExamList(prourlid);
                //proid = resdata[1].split("=")[1];
            } else {
                //prourlid = resdata[0].split("=")[1];
                //alert(444);
                //alert(prourlid);
                //AdminName = resdata[1].split("=")[1];
                //Password = resdata[2].split("Pwd=")[1];
            }
         
        }
    
       
    });
  
  


    var examids = [];
    //获取Mooc对应课程习题列表
    function GetExamList(id) {
        var obj = {};
        obj.Cid = id
        $.ajax({
            url: '../../Exam/GetCourse_ExamList',
            type: 'Get',
            async: true,
            data: obj,
            headers: {
                "token": sessionStorage.getItem("NewToken")
            },
            contentType: 'application/json',
            success: function (data) {
                var resultData = JSON.parse(data);
                if (resultData != undefined) {
                    var Str = "";
                    if (resultData.length > 0) {
                        for (var i = 0; i < resultData.length; i++) {
                            //var ts = {};
                            //ts.Id = resultData[i].Id;
                            //ts.TopicType = resultData[i].TopicType;
                            //ts.RightAnswer = resultData[i].RightAnswer;
                            //examids.push(ts);
                            if (resultData[i].TopicType == 1) {
                                $("#ids").val(resultData[i].Id);
                                //Str += ' <div class="task"><div class="toppic"><b></b><p>第' + (i + 1) + '题</p></div><div class="editbox"><div class="edit_li"><div class="title"><sup></sup>习题类型：</div><div class="cont"><input type="radio" name="examtype_' + resultData[i].Id + '" value="1" title="单选"  lay-filter="examtype_' + resultData[i].Id + '"><input type="radio" name="examtype_' + resultData[i].Id + '" value="2" title="多选" lay-filter="examtype_' + resultData[i].Id + '"></div></div><div class="edit_li" id="title' + resultData[i].Id + '"><div class="title"><sup></sup>题目内容：</div><div class="cont"><input id="Topic_' + resultData[i].Id + '" name="workname" type="text" class="input_def" value="' + resultData[i].Topic + '" placeholder="输入题目内容" /></div></div><div class="edit_li"><div class="title">题目图片：</div><div class="cont">  <div class="layui-upload"><button type="button" class="layui-btn layui-btn-normal" id="test_' + resultData[i].Id + '">上传图片</button><span class="layui-word-aux">图片大小：290px*163px</span><span id="imgname_' + resultData[i].Id + '">    </span><div class="layui-upload-list"><img class="layui-upload-img layui-upload-course-kpoints" id="demo1_' + resultData[i].Id + '"><p id="demoText_' + resultData[i].Id + '"></p></div><div style="width: 95px;"><div class="layui-progress layui-progress-big" lay-showpercent="yes" lay-filter="demo_' + resultData[i].Id + '"><div class="layui-progress-bar" lay-percent=""></div></div></div></div></div></div><DIV id="type1_' + resultData[i].Id + '" style=""><div class="edit_li"><div class="title">A:</div><div class="cont"><input id="OptionA_' + resultData[i].Id + '" name="ExamAmswer" type="text" class="input_def" value="' + resultData[i].OptionA + '" placeholder="输入选项内容" /></div></div><div class="edit_li"><div class="title">B:</div><div class="cont"><input id="OptionB_' + resultData[i].Id + '" name="ExamAmswer" type="text" class="input_def" value="' + resultData[i].OptionB + '" placeholder="输入选项内容" /></div></div><div class="edit_li"><div class="title">C:</div><div class="cont"><input id="OptionC_' + resultData[i].Id + '" name="ExamAmswer" type="text" class="input_def" value="' + resultData[i].OptionC + '" placeholder="输入选项内容" /></div></div><div class="edit_li"><div class="title">D:</div><div class="cont"><input id="OptionD_' + resultData[i].Id + '" name="ExamAmswer" type="text" class="input_def" value="' + resultData[i].OptionD + '" placeholder="输入选项内容" /></div></div><div class="edit_li"><div class="title">E:</div><div class="cont"><input id="OptionE_' + resultData[i].Id + '" name="ExamAmswer" type="text" class="input_def" value="' + resultData[i].OptionE + '" placeholder="输入选项内容" /></div></div><div class="edit_li"><div class="title"><sup></sup>正确答案：</div><div class="cont"><input type="radio" name="Answer1_' + resultData[i].Id + '" value="A" title="A" /><input type="radio" name="Answer1_' + resultData[i].Id + '" value="B" title="B" /><input type="radio" name="Answer1_' + resultData[i].Id + '" value="C" title="C" /><input type="radio" name="Answer1_' + resultData[i].Id + '" value="D" title="D" /><input type="radio" name="Answer1_' + resultData[i].Id + '" value="E" title="E" /></div></div></DIV><DIV id="type2_' + resultData[i].Id + '" style="display:none"><div class="edit_li"><div class="title">A:</div><div class="cont"><input id="OptionA2_' + resultData[i].Id + '" name="ExamAmswer" type="text" class="input_def" value="' + resultData[i].OptionA + '" placeholder="输入选项内容" /></div></div><div class="edit_li"><div class="title">B:</div><div class="cont"><input id="OptionB2_' + resultData[i].Id + '" name="ExamAmswer" type="text" class="input_def" value="' + resultData[i].OptionB + '" placeholder="输入选项内容" /></div></div><div class="edit_li"><div class="title">C:</div><div class="cont"><input id="OptionC2_' + resultData[i].Id + '" name="ExamAmswer" type="text" class="input_def" value="' + resultData[i].OptionC + '" placeholder="输入选项内容" /></div></div><div class="edit_li"><div class="title">D:</div><div class="cont"><input id="OptionD2_' + resultData[i].Id + '" name="ExamAmswer" type="text" class="input_def" value="' + resultData[i].OptionD + '" placeholder="输入选项内容" /></div></div><div class="edit_li"><div class="title">E:</div><div class="cont"><input id="OptionE2_' + resultData[i].Id + '" name="ExamAmswer" type="text" class="input_def" value="' + resultData[i].OptionE + '" placeholder="输入选项内容" /></div></div><div class="edit_li"><div class="title"><sup></sup>正确答案：</div><div class="cont"><input type="checkbox" name="Answer2_' + resultData[i].Id + '" value="A" title="A" /><input type="checkbox" name="Answer2_' + resultData[i].Id + '" value="B" title="B" /><input type="checkbox" name="Answer2_' + resultData[i].Id + '" value="C" title="C" /><input type="checkbox" name="Answer2_' + resultData[i].Id + '" value="D" title="D" /><input type="checkbox" name="Answer2_' + resultData[i].Id + '" value="E" title="E" /></div></div></DIV><DIV id="type3_' + resultData[i].Id + '" style="display:none"><div class="edit_li"><div class="title"><sup></sup>正确答案：</div><div class="cont"><input type="radio" name="Answer3_' + resultData[i].Id + '" value="0" title="正确" /><input type="radio" name="Answer3_' + resultData[i].Id + '" value="1" title="错误" /></div></div></DIV><DIV id="type4_' + resultData[i].Id + '" style="display:none" ><div class="edit_li"><div class="title"><sup></sup>填空设置：</div><div class="cont"><textarea class="layui-textarea" id="LAY_demo_' + resultData[i].Id + '" style="display: none;"></textarea><button type="button" class="layui-btn layui-btn-normal" id="exambtn" onclick="AddTextExam(' + resultData[i].Id + ')">增加填空</button><br /></div><div class="cont" style="float:right">正确答案<div id="TKinput_' + resultData[i].Id + '"></div></div></div></DIV><div id="btn_1" class="btnbox"><a class="btn_red_m style1" onclick="UpdateExam(' + resultData[i].Id + ')">修改</a>&nbsp;&nbsp;&nbsp;<a class="btn_red_m style1" onclick="Del(' + resultData[i].Id + ')">删除</a></div></div></div>';
                                $("#Topic_").val(resultData[i].Topic);
                                $("#OptionA_").val(resultData[i].OptionA);
                                $("#OptionB_").val(resultData[i].OptionB);
                                $("#OptionC_").val(resultData[i].OptionC);
                                $("#OptionD_").val(resultData[i].OptionD);
                                $("#OptionE_").val(resultData[i].OptionE);
                                $("#btn_save").hide();
                                $("#btn_updateDel").show();
                                $("input[name=Answer1_][value=" + resultData[i].RightAnswer + "]").prop("checked", "true");
                               /* $(".Answer1_").prop("");*/
                                layui.use(['form', 'layer', 'upload'], function () {
                                    var form = layui.form
                                    form.render();
                                });
                            }
                        }
                    } else {

                        $("#Topic_").val("");
                        $("#OptionA_").val("");
                        $("#OptionB_").val("");
                        $("#OptionC_").val("");
                        $("#OptionD_").val("");
                        $("#OptionE_").val("");
                        $("#imgname_").text("");

                        $("#btn_save").show();
                        $("#btn_updateDel").hide();
                        

                    }
               
                   /* $("#homework").append(Str)*/
                   // $("#homework").append('<a id="btn_work_add" class="btn_task_add"><b></b></a>')
              
              
                  
                        //$("input[name=examtype_" + examids[i].Id + "][value=" + examids[i].TopicType + "]").prop("checked", "true");
                        //var checkboxstr = examids[i].RightAnswer.split(',')
                        //if (examids[i].TopicType == 1) {
                        //    $("input[name=Answer1_" + examids[i].Id + "][value=" + examids[i].RightAnswer + "]").prop("checked", "true");
                        //} 
                        //layui.use(['form', 'layer', 'upload', 'element', 'layedit'], function () {
                        //    var form = layui.form
                        //    form.render();
                        //});



                    }
                
            },
            complete: function () {

                //增加一个任务
                //$("#btn_work_add").click(function () {
                //    answercount = 1;
                //    var Id = 0;

                //    if (sessionStorage.getItem("tabid") == 909) {
                //        sessionStorage.setItem("tabid", Number(sessionStorage.getItem("tabid")) + 1)
                //        Id = sessionStorage.getItem("tabid")
                //    } else {
                //        sessionStorage.setItem("tabid", Number(sessionStorage.getItem("tabid")) + 1)
                //        Id = sessionStorage.getItem("tabid")
                //    }
                //    var Str1 = "";
                //    //<div class="layui-input-block"></div>
                //    Str1 += ' <div class="task"><div class="toppic"><b></b><p></p></div><div class="editbox"><div class="edit_li"><div class="title"><sup></sup>习题类型：</div><div class="cont"><input type="radio" name="examtype_' + Id + '" value="1" title="单选"  lay-filter="examtype_' + Id + '" checked><input type="radio" name="examtype_' + Id + '" value="2" title="多选" lay-filter="examtype_' + Id + '"><input type="radio" name="examtype_' + Id + '" value="3" title="判断" lay-filter="examtype_' + Id + '"><input type="radio" name="examtype_' + Id + '" value="4" title="填空" lay-filter="examtype_' + Id + '"></div></div><div class="edit_li" id="title_' + Id + '"><div class="title"><sup></sup>题目内容：</div><div class="cont"><input id="Topic_' + Id + '" name="workname" type="text" class="input_def" value="" placeholder="输入题目内容" /></div></div><div class="edit_li"><div class="title">题目图片：</div><div class="cont"> <div class="layui-upload"><button type="button" class="layui-btn layui-btn-normal" id="test_' + Id + '">上传图片</button><span class="layui-word-aux">图片大小：290px*163px</span><span id="imgname_' + Id + '">    </span><div class="layui-upload-list"><img class="layui-upload-img layui-upload-course-kpoints" id="demo1_' + Id + '"><span id="demoText_' + Id + '"></span></div><div style="width: 95px;"><div class="layui-progress layui-progress-big" lay-showpercent="yes" lay-filter="demo_' + Id + '"><div class="layui-progress-bar" lay-percent=""></div></div></div></div></div></div><DIV id="type1_' + Id + '"><div class="edit_li"><div class="title">A:</div><div class="cont"><input id="OptionA_' + Id + '" name="ExamAmswer" type="text" class="input_def" value="" placeholder="输入选项内容" /></div></div><div class="edit_li"><div class="title">B:</div><div class="cont"><input id="OptionB_' + Id + '" name="ExamAmswer" type="text" class="input_def" value="" placeholder="输入选项内容" /></div></div><div class="edit_li"><div class="title">C:</div><div class="cont"><input id="OptionC_' + Id + '" name="ExamAmswer" type="text" class="input_def" value="" placeholder="输入选项内容" /></div></div><div class="edit_li"><div class="title">D:</div><div class="cont"><input id="OptionD_' + Id + '" name="ExamAmswer" type="text" class="input_def" value="" placeholder="输入选项内容" /></div></div><div class="edit_li"><div class="title">E:</div><div class="cont"><input id="OptionE_' + Id + '" name="ExamAmswer" type="text" class="input_def" value="" placeholder="输入选项内容" /></div></div><div class="edit_li"><div class="title"><sup></sup>正确答案：</div><div class="cont"><input type="radio" name="Answer1_' + Id + '" value="A" title="A" /><input type="radio" name="Answer1_' + Id + '" value="B" title="B" /><input type="radio" name="Answer1_' + Id + '" value="C" title="C" /><input type="radio" name="Answer1_' + Id + '" value="D" title="D" /><input type="radio" name="Answer1_' + Id + '" value="E" title="E" /></div></div></DIV><DIV id="type2_' + Id + '" style="display:none"><div class="edit_li"><div class="title">A:</div><div class="cont"><input id="OptionA2_' + Id + '" name="ExamAmswer" type="text" class="input_def" value="" placeholder="输入选项内容" /></div></div><div class="edit_li"><div class="title">B:</div><div class="cont"><input id="OptionB2_' + Id + '" name="ExamAmswer" type="text" class="input_def" value="" placeholder="输入选项内容" /></div></div><div class="edit_li"><div class="title">C:</div><div class="cont"><input id="OptionC2_' + Id + '" name="ExamAmswer" type="text" class="input_def" value="" placeholder="输入选项内容" /></div></div><div class="edit_li"><div class="title">D:</div><div class="cont"><input id="OptionD2_' + Id + '" name="ExamAmswer" type="text" class="input_def" value="" placeholder="输入选项内容" /></div></div><div class="edit_li"><div class="title">E:</div><div class="cont"><input id="OptionE2_' + Id + '" name="ExamAmswer" type="text" class="input_def" value="" placeholder="输入选项内容" /></div></div><div class="edit_li"><div class="title"><sup></sup>正确答案：</div><div class="cont"><input type="checkbox" name="Answer2_' + Id + '" value="A" title="A" /><input type="checkbox" name="Answer2_' + Id + '" value="B" title="B" /><input type="checkbox" name="Answer2_' + Id + '" value="C" title="C" /><input type="checkbox" name="Answer2_' + Id + '" value="D" title="D" /><input type="checkbox" name="Answer2_' + Id + '" value="E" title="E" /></div></div></DIV><DIV id="type3_' + Id + '" style="display:none"><div class="edit_li"><div class="title"><sup></sup>正确答案：</div><div class="cont"><input type="radio" name="Answer3_' + Id + '" value="0" title="正确" /><input type="radio" name="Answer3_' + Id + '" value="1" title="错误" /></div></div></DIV><DIV id="type4_' + Id + '" style="display:none"><div class="edit_li"><div class="title"><sup></sup>填空设置：</div><div class="cont"><textarea class="layui-textarea" id="LAY_demo_' + Id + '" style="display: none;"></textarea><button type="button" class="layui-btn layui-btn-normal" id="exambtn" onclick="AddTextExam(' + Id + ')">增加填空</button><br /></div><div class="cont" style="float:right">正确答案<div id="TKinput_' + Id + '"></div></div></div></DIV><div id="btn_1_' + Id + '" class="btnbox"><a class="btn_red_m style1" onclick="save(' + Id + ',' + id + ')">保存</a>&nbsp;&nbsp;&nbsp;</div></div></div>';

                //    $("#btn_work_add").before(Str1);
                //    var num = $("#homework").children(".task").length;

                //    $("#homework").children(".task:last").find("p").html("新增习题");
                //    layui.use(['form', 'layer', 'upload', 'element'], function () {
                //        var form = layui.form, layer = layui.layer, upload = layui.upload, element = layui.element, layedit = layui.layedit
                    
                //        sessionStorage.setItem("index" + Id + "", index)
                //        form.render();
                //        form.on('radio(examtype_' + Id + ')', function (data) {
                //            var fid = (this.name).split('_')[1]
                //            if (this.value == 1) {
                //                $("#type1_" + fid + "").css("display", "")
                //                $("#type2_" + fid + "").css("display", "none")
                //                $("#type3_" + fid + "").css("display", "none")
                //                $("#type4_" + fid + "").css("display", "none")
                //                $("#title_" + Id + "").css("display", "")
                //            } else if (this.value == 2) {
                //                $("#type1_" + fid + "").css("display", "none")
                //                $("#type2_" + fid + "").css("display", "")
                //                $("#type3_" + fid + "").css("display", "none")
                //                $("#type4_" + fid + "").css("display", "none")
                //                $("#title_" + Id + "").css("display", "")
                //            }
                //        })

                //        var uploadInst = upload.render({
                //            elem: '#test_' + Id + ''
                //            , url: virualpath + 'Project/uploadExamImg' //改成您自己的上传接口
                //            , headers: {
                //                "token": sessionStorage.getItem("NewToken")
                //            }
                //            , before: function (obj) {
                //                //预读本地文件示例，不支持ie8
                //                obj.preview(function (index, file, result) {
                //                    $('#demo1_' + Id + '').attr('src', result); //图片链接（base64）
                //                });

                //                element.progress('demo1_' + Id + '', '0%'); //进度条复位
                //                layer.msg('上传中', { icon: 16, time: 0 });
                //            }
                //            , done: function (res) {
                //                $("#imgname_" + Id + "").text(res.fileName)
                //                //如果上传失败
                //                if (res.code > 0) {
                //                    return layer.msg('上传失败');
                //                }
                //                //上传成功的一些操作
                //                //……
                //                $('#demoText_' + Id + '').html(''); //置空上传失败的状态
                //            }
                //            , error: function () {
                //                //演示失败状态，并实现重传
                //                var demoText = $('#demoText_' + Id + '');
                //                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                //                demoText.find('.demo-reload').on('click', function () {
                //                    uploadInst.upload();
                //                });
                //            }
                //            //进度条
                //            , progress: function (n, elem, e) {
                //                element.progress('demo1_' + Id + '', n + '%'); //可配合 layui 进度条元素使用
                //                if (n == 100) {
                //                    layer.msg('上传完毕', { icon: 1 });
                //                }
                //            }
                //        })

                //    })

                //    var dateFormat = "yy-mm-dd",
                //        from = $("#sid_" + num)
                //            .datepicker({
                //                defaultDate: "+1w",
                //                changeMonth: true,
                //                numberOfMonths: 1,

                //            })
                //            .on("change", function () {
                //                to.datepicker("option", "minDate", getDate(this));
                //            }),
                //        to = $("#eid_" + num).datepicker({
                //            defaultDate: "+1w",
                //            changeMonth: true,
                //            numberOfMonths: 1,

                //        })
                //            .on("change", function () {
                //                from.datepicker("option", "maxDate", getDate(this));
                //            });

                //    function getDate(element) {
                //        var date;
                //        try {
                //            date = $.datepicker.parseDate(dateFormat, element.value);
                //        } catch (error) {
                //            date = null;
                //        }

                //        return date;
                //    }



                //});
            }
        })
    }
    //var answercount = 1;
    //function AddTextExam(id) {
    //    layui.use(['form', 'layedit'], function () {
    //        var form = layui.form, layedit = layui.layedit;
    //        layedit.setContent(sessionStorage.getItem("index" + id + ""), layedit.getContent(sessionStorage.getItem("index" + id + "")) + "<span>" + answercount + "(____)</span>");
    //        var str = layedit.getText(sessionStorage.getItem("index" + id + ""));
    //        var str1 = str.split("(____)")
    //        console.log(str1)
    //        $("#TKinput_" + id + "").append("" + answercount + "：<input name='answer4_" + id + "' type='text'><br/>")
    //        answercount++;
    //    });

    //}

    ////新增测试题
    //function save(id, cid) {
    //    var obj = {};
    //    obj.CourseId = cid;
    //    obj.Topic = $("#Topic_" + id + "").val();
    //    obj.Img = $("#imgname_" + id + "").text();
    //    obj.TopicType = $('input[name ="examtype_' + id + '"]').filter(':checked').val();
    //    if (obj.TopicType == 1) {
    //        obj.OptionA = $("#OptionA_" + id + "").val();
    //        obj.OptionB = $("#OptionB_" + id + "").val();
    //        obj.OptionC = $("#OptionC_" + id + "").val();
    //        obj.OptionD = $("#OptionD_" + id + "").val();
    //        obj.OptionE = $("#OptionE_" + id + "").val();
    //        obj.OptionTrue = 0;
    //        obj.OptionFalse = 0;
    //        obj.RightAnswer = $('input[name ="Answer1_' + id + '"]').filter(':checked').val();
    //        switch (true) {
    //            case $('input[name ="Answer1_' + id + '"]').filter(':checked').val() == 'A':
    //                obj.RightAnswerText = obj.OptionA
    //                break;
    //            case $('input[name ="Answer1_' + id + '"]').filter(':checked').val() == 'B':
    //                obj.RightAnswerText = obj.OptionB
    //                break;
    //            case $('input[name ="Answer1_' + id + '"]').filter(':checked').val() == 'C':
    //                obj.RightAnswerText = obj.OptionC
    //                break;
    //            case $('input[name ="Answer1_' + id + '"]').filter(':checked').val() == 'D':
    //                obj.RightAnswerText = obj.OptionD
    //                break;
    //            case $('input[name ="Answer1_' + id + '"]').filter(':checked').val() == 'E':
    //                obj.RightAnswerText = obj.OptionE
    //                break;
    //        }
    //        obj.Score = 1;
    //    } else if (obj.TopicType == 2) {
    //        obj.OptionA = $("#OptionA2_" + id + "").val();
    //        obj.OptionB = $("#OptionB2_" + id + "").val();
    //        obj.OptionC = $("#OptionC2_" + id + "").val();
    //        obj.OptionD = $("#OptionD2_" + id + "").val();
    //        obj.OptionE = $("#OptionE2_" + id + "").val();
    //        obj.OptionTrue = 0;
    //        obj.OptionFalse = 0;
    //        var arr = '';
    //        var arr1 = [];
    //        if ($('input[name="Answer2_' + id + '"]:checked').val() == null) {
    //            obj.RigheAnswer = null;
    //            console.log('obj.RigheAnswer = null')
    //        } else {
    //            $('input[name="Answer2_' + id + '"]:checked').each(function (i) {
    //                if (arr == "") {
    //                    arr = $(this).val();
    //                } else {
    //                    arr += "," + $(this).val() + "";
    //                }
    //                switch (true) {
    //                    case $(this).val() == 'A':
    //                        arr1.push(obj.OptionA);
    //                        break;
    //                    case $(this).val() == 'B':
    //                        arr1.push(obj.OptionB);
    //                        break;
    //                    case $(this).val() == 'C':
    //                        arr1.push(obj.OptionC);
    //                        break;
    //                    case $(this).val() == 'D':
    //                        arr1.push(obj.OptionD);
    //                        break;
    //                    case $(this).val() == 'E':
    //                        arr1.push(obj.OptionE);
    //                        break;
    //                }
    //            });
    //            obj.RightAnswer = arr;
    //            obj.RightAnswerText = arr1.join(',');
    //        }
    //        obj.Score = 1;
    //    } else if (obj.TopicType == 3) {
    //        obj.OptionA = "";
    //        obj.OptionB = "";
    //        obj.OptionC = "";
    //        obj.OptionD = "";
    //        obj.OptionE = "";
    //        obj.OptionTrue = 0;
    //        obj.OptionFalse = 0;
    //        obj.RightAnswer = $('input[name ="Answer3_' + id + '"]').filter(':checked').val();
    //        obj.Score = 1;
    //    } else if (obj.TopicType == 4) {
    //        layui.use(['form', 'layedit'], function () {
    //            var form = layui.form, layedit = layui.layedit;
    //            var index = sessionStorage.getItem("index" + id + "");
    //            var str = layedit.getText(index);
    //            var str1 = layedit.getContent(index)
    //            obj.OptionTrue = str;
    //        });
    //        var answerStr = "";
    //        $("input[name='answer4_" + id + "']").each(function () {
    //            if (answerStr == "") {
    //                answerStr = $(this).val();
    //            } else {
    //                answerStr += "、" + $(this).val();
    //            }
    //        });
    //        obj.RightAnswer = answerStr;
    //    }

    //    if (obj.Topic == "" & obj.TopicType != 4) {
    //        alert("请填写题目");
    //        return;
    //    }
    //    $.ajax({
    //        url: virualpath + 'Exam/InsertExamitem',
    //        type: 'post',
    //        data: JSON.stringify(obj),
    //        dataType: 'json',
    //        headers: {
    //            "token": sessionStorage.getItem("NewToken")
    //        },
    //        contentType: 'application/json',
    //        async: false,
    //        success: function (data) {
    //            if (data == 1) {
    //                alert("添加成功")
    //                $("#btn_1_" + id + "").css("display", "none")
    //            } else {
    //                alert("添加失败")
    //            }
    //        }
    //    })

    //}

    //修改测试题
    function UpdateExam() {
        if (confirm("确认修改吗")) {
            if ($("#ids").val() > 0) {
                var obj = {};
                obj.Id = $("#ids").val();
                obj.Topic = $("#Topic_").val();
                obj.Img = $("#imgname_").text();
                // obj.TopicType = $('input[name ="examtype_' + id + '"]').filter(':checked').val();

                obj.TopicType = 1;
                obj.OptionA = $("#OptionA_").val();
                obj.OptionB = $("#OptionB_").val();
                obj.OptionC = $("#OptionC_").val();
                obj.OptionD = $("#OptionD_").val();
                obj.OptionE = $("#OptionE_").val();
                obj.OptionTrue = 0;
                obj.OptionFalse = 0;
                obj.RightAnswer = $('input[name ="Answer1_"]').filter(':checked').val();
                switch (true) {
                    case $('input[name ="Answer1_"]').filter(':checked').val() == 'A':
                        obj.RightAnswerText = obj.OptionA
                        break;
                    case $('input[name ="Answer1_"]').filter(':checked').val() == 'B':
                        obj.RightAnswerText = obj.OptionB
                        break;
                    case $('input[name ="Answer1_"]').filter(':checked').val() == 'C':
                        obj.RightAnswerText = obj.OptionC
                        break;
                    case $('input[name ="Answer1_"]').filter(':checked').val() == 'D':
                        obj.RightAnswerText = obj.OptionD
                        break;
                    case $('input[name ="Answer1_"]').filter(':checked').val() == 'E':
                        obj.RightAnswerText = obj.OptionE
                        break;
                }
                /*  obj.Score = 1;*/

                $.ajax({
                    url: virualpath + 'Exam/UpdateExaminfo',
                    type: 'post',
                    data: JSON.stringify(obj),
                    dataType: 'json',
                    headers: {
                        "token": sessionStorage.getItem("NewToken")
                    },
                    contentType: 'application/json',
                    async: false,
                    success: function (data) {
                        if (data == 1) {
                            alert("修改成功");
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.location.reload();//刷新父页面，注意一定要在关闭当前iframe层之前执行刷新
                            parent.layer.close(index); //再执行关闭
                        } else {
                            alert("修改失败");
                        }
                    }
                })
            }
        }
    }

    function Del() {
        if ($("#ids").val() > 0) {
            var obj = {};
            obj.Id = $("#ids").val();
            if (confirm("确认删除吗")) {
                $.ajax({
                    url: virualpath + 'Exam/DeleteExaminfo',
                    type: 'post',
                    data: JSON.stringify(obj),
                    headers: {
                        "token": sessionStorage.getItem("NewToken")
                    },
                    dataType: 'json',
                    contentType: 'application/json',
                    async: false,
                    success: function (data) {
                        if (data == 1) {
                            alert("删除成功");
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.location.reload();//刷新父页面，注意一定要在关闭当前iframe层之前执行刷新
                            parent.layer.close(index); //再执行关闭
                        } else {
                            alert("删除失败");
                        }
                    }
                })
            }
        }
    }

    layui.use(['element', 'layer', 'upload'], function () {
       // var form = layui.form, layer = layui.layer, upload = layui.upload;
     /*   var $ = layui.jquery*/
        var upload = layui.upload
           ,form = layui.form
            ,element = layui.element
            , layer = layui.layer;
        //上传作业图片
        var uploadInst = upload.render({
            elem: '#test_'
            , url: virualpath + 'Project/uploadExamImg' //改成您自己的上传接口
            , headers: {
                "token": sessionStorage.getItem("NewToken")
            }
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo1_').attr('src', result); //图片链接（base64）
                });

                element.progress('demo1_', '0%'); //进度条复位
                layer.msg('上传中', { icon: 16, time: 0 });
            }
            , done: function (res) {
              
                if (res.msg == "上传成功") {

                    $("#imgname_").text(res.fileName)
                   /* $('.layui-progress').css('background-color', '#5FB878');*/
                }

                //如果上传失败
                else {
                     $('#demoText_').html(''); //置空上传失败的状态
                    return layer.msg(res.msg);
                }
               
               
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText_');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
            //进度条
            , progress: function (n, elem, e) {
                element.progress('demo1_', n + '%'); //可配合 layui 进度条元素使用
                if (n == 100) {
                    layer.msg('上传完毕', { icon: 1 });
                }
            }
        });
       
    })

    function saves() {
        var obj = {};
        obj.CourseId = prourlid;
        obj.Topic = $("#Topic_").val();
        obj.TopicType = 1;
        obj.Img = $("#imgname_").text();
        obj.OptionA = $("#OptionA_").val();
        obj.OptionB = $("#OptionB_").val();
        obj.OptionC = $("#OptionC_").val();
        obj.OptionD = $("#OptionD_").val();
        obj.OptionE = $("#OptionE_").val();
        obj.OptionTrue = 0;
        obj.OptionFalse = 0;
        obj.RightAnswer = $('input[name ="Answer1_"]').filter(':checked').val();
        switch (true) {
            case $('input[name ="Answer1_"]').filter(':checked').val() == 'A':
                obj.RightAnswerText = obj.OptionA;
              /*  obj.RightAnswer = obj.OptionA;*/
                break;
            case $('input[name ="Answer1_"]').filter(':checked').val() == 'B':
                obj.RightAnswerText = obj.OptionB;
                /*obj.RightAnswer = obj.OptionB;*/
                break;
            case $('input[name ="Answer1_"]').filter(':checked').val() == 'C':
                obj.RightAnswerText = obj.OptionC;
               // obj.RightAnswer = obj.OptionC;
                break;
            case $('input[name ="Answer1_"]').filter(':checked').val() == 'D':
                obj.RightAnswerText = obj.OptionD;
               // obj.RightAnswer = obj.OptionD;
                break;
            case $('input[name ="Answer1_"]').filter(':checked').val() == 'E':
                obj.RightAnswerText = obj.OptionE;
               // obj.RightAnswer = obj.OptionE;
                break;
        }
         $.ajax({
             url: virualpath + 'Exam/InsertExamitem',
             type: 'post',
             data: JSON.stringify(obj),
             dataType: 'json',
             headers: {
                 "token": sessionStorage.getItem("NewToken")
             },
             contentType: 'application/json',
             async: false,
             success: function (data) {
                 if (data == 1) {
                     alert("添加成功")
                     var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                     parent.location.reload();//刷新父页面，注意一定要在关闭当前iframe层之前执行刷新
                     parent.layer.close(index); //再执行关闭
                     //$("#btn_1_" + id + "").css("display", "none")
                 } else {
                     alert("添加失败")
                 }
             }
         });
    }


</script>